from django.shortcuts import render
from django.views import View

from goods.models import *
from .utils import get_menu
from .models import ContentCategory, Content


class Index(View):

    def get(self,request):
        message_lbt = Content.objects.filter(category__key = "index_lbt",status=True).order_by("sequence")
        message_kx = Content.objects.filter(category__key="index_kx",status=True).order_by("sequence")
        """一楼数据"""
        content_1_logo = Content.objects.filter(category__key="index_1f_logo",status=True).order_by("sequence")
        content_1_channel = Content.objects.filter(category__key="index_1f_pd",status=True).order_by("sequence")
        content_1_tag = Content.objects.filter(category__key="index_1f_bq",status=True).order_by("sequence")
        content_1_new = Content.objects.filter(category__key="index_1f_ssxp",status=True).order_by("sequence")
        """二楼数据"""
        content_2_logo = Content.objects.filter(category__key="index_2f_logo",status=True).order_by("sequence")
        content_2_channel = Content.objects.filter(category__key="index_2f_pd",status=True).order_by("sequence")
        content_2_tag = Content.objects.filter(category__key="index_2f_bq",status=True).order_by("sequence")
        content_2_new = Content.objects.filter(category__key="index_2f_jjhg",status=True).order_by("sequence")
        """三楼数据"""
        content_3_logo = Content.objects.filter(category__key="index_3f_logo",status=True).order_by("sequence")
        content_3_channel = Content.objects.filter(category__key="index_3f_pd",status=True).order_by("sequence")
        content_3_tag = Content.objects.filter(category__key="index_3f_bq",status=True).order_by("sequence")
        content_3_new = Content.objects.filter(category__key="index_3f_shyp",status=True).order_by("sequence")

        context = {
            "good_all_kinds":get_menu(),
            "content":{
                "lbts" : message_lbt,    # 轮播图视频
                "kxs":message_kx,       # 快讯

                "content_1":{       # 一楼数据
                    "logos":content_1_logo,
                    "channels":content_1_channel,
                    "tags":content_1_tag,
                    "news":content_1_new,
                },
                "content_2":{     # 二楼数据
                    "logos": content_2_logo,
                    "channels": content_2_channel,
                    "tags": content_2_tag,
                    "news": content_2_new,
                },
                "content_3": {  # 三楼数据
                    "logos": content_3_logo,
                    "channels": content_3_channel,
                    "tags": content_3_tag,
                    "news": content_3_new,
                },
            }
        }
        return render(request,"index.html",context)
"""
数据结构  
"good-all_kinds":{
"1":{"cat1":[一级目录],"cat2":[二级目录"]},  # 第一频道
"2":{"cat1":[一级目录],"cat2":[二级目录"]},  # 第二频道
.........
三级目录数据在渲染时生成并遍历
.........
"content":{
"lbt":[],   # 轮播图
"kx":[],    # 快讯

"""
# class Content(View):
#     def get(self,request):
#         good_all_kinds = GoodsChannel.objects.all().order_by("group_id","sequence")
#         count = GoodsChannelGroup.objects.all().count()
#         good_all_kind = []
#
#         for i in range(count):
#             # 根据频道数创建频道列表
#             good_all_kind.append([])
#         for cat1 in good_all_kinds:
#             # 遍历一级目录添加到对应频道列表中
#             good_all_kind[cat1.group_id-1].append(cat1)
#             cat1.cat = []
#             for cat2 in cat1.category.subs.all():
#                 cat1.cat.append(cat2)
#
#         context = {
#             "good_all_kind": good_all_kind,
#             "content": "广告数据"
#         }
#         return render(request, "content.html", context)
""" 
数据结构
一级目录
”good_all_kind":[一级目录....]

二级目录 ：设置二级目录为一级目录的一个属性
一级目录.subset=[二级目录...]

三级目录 ： 设置三级目录为二级目录的一个属性
二级目录.subset=[三级目录...]
"""


